﻿using System;
using System.Drawing;

namespace MarioMapEditor
{
    class ObAcEnemy1 : ObActive
    {
        public enum ENERMY1 { RUAXANH = 65, RUADO, RUANEMDA, BAYTRENTROI };
        public enum RUAINFO { LV1_LEFT = 5, LV1_RIGHT, LV2_LEFT, LV2_RIGHT};
        public ObAcEnemy1(){
            ID      = 0;
            Info    = (int)INFO.LEFT;
            Width   = 1;
            Height  = 2;
        }

        public ObAcEnemy1(ENERMY1 nid)
        {
            ID = (int)nid;
            Info = (int)INFO.LEFT;
            Width = 1;
            Height = 2;

            if (nid == ENERMY1.RUADO || nid == ENERMY1.RUAXANH)
            {
                Info = (int)RUAINFO.LV1_LEFT;
            }
        }

        public ObAcEnemy1(ENERMY1 nid, INFO nInfo)
        {
            ID      = (int)nid;
            Info    = (int)nInfo;
            Width   = 1;
            Height  = 2;
        }

        public ObAcEnemy1(ENERMY1 nid, RUAINFO nInfo)
        {
            ID = (int)nid;
            Info = (int)nInfo;
            Width = 1;
            Height = 2;
        }

        public override bool SetID(int nID)
        {
            if (checkType(nID))
            {
                ID = nID;
                return true;
            }
            return false;
        }

        public override bool SetINFO(int nInfo)
        {
            if (ID == (int)ENERMY1.RUADO || ID == (int)ENERMY1.RUAXANH)
            {
                if (Enum.IsDefined(typeof(RUAINFO), nInfo))
                {
                    Info = nInfo;
                    return true;
                }
                return false;
            }
            if (Enum.IsDefined(typeof(INFO), nInfo))
            {
                Info = nInfo;
                return true;
            }
            return false;
        }

        public static bool checkType(int objectID)
        {
            if (Enum.IsDefined(typeof(ENERMY1), objectID))
            {
                return true;
            }
            return false;
        }

        public static int selectEnermy(int x)
        {
            switch (x)
            {
                case 0:
                    return (int)ENERMY1.RUAXANH;
                case 1:
                    return (int)ENERMY1.RUADO;
                case 2:
                    return (int)ENERMY1.RUANEMDA;
                case 3:
                    return (int)ENERMY1.BAYTRENTROI;
                default:
                    return 0;
            }
        }

        public override Bitmap GetBitmap()
        {
            if (!checkType(ID))
            {
                return null;
            }
            var cropRect = new Rectangle(0, 0, MainForm.FileSize * Width, MainForm.FileSize * Height);
            switch (ID)
            {
                case (int)ENERMY1.RUAXANH:
                    cropRect = new Rectangle(0, 0, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY1.RUADO:
                    cropRect = new Rectangle(MainForm.FileSize, 0, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY1.RUANEMDA:
                    cropRect = new Rectangle(MainForm.FileSize*2, 0, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY1.BAYTRENTROI:
                    cropRect = new Rectangle(MainForm.FileSize*3, 0, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
            }
            var src = Properties.Resources.Enermy1;
            var trg = new Bitmap(Width * MainForm.TileSize, Height * MainForm.TileSize);
            using (var g = Graphics.FromImage(trg))
            {
                g.DrawImage(src, new Rectangle(0, 0, trg.Width, trg.Height), cropRect, GraphicsUnit.Pixel);
            }
            return trg;
        }
    }
}
